package com.easy.controllor;

import com.easy.bean.Order;
import com.easy.bean.OrderDetail;
import com.easy.bean.User;
import com.easy.service.OrderDetailService;
import com.easy.util.Page;
import com.easy.util.Result;
import com.easy.util.SYS;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/orderDetail")
public class OrderDetailControllor {
    @Autowired
    OrderDetailService orderDetailService;

    @PostMapping("/uncommit")
    public Result add(@RequestBody OrderDetail orderDetail) {
        Object obj = orderDetailService.add( orderDetail);
        return Result.success(obj);
    }

    @DeleteMapping("/uncommit/{id}")
    public Result del(@PathVariable("id") Integer id){
        Object obj = orderDetailService.del(id);
        return Result.success(obj);
    }
    @DeleteMapping("/finish/{orderId}")
    public Result finishdel(@PathVariable("orderId") String orderId){
        Object obj = orderDetailService.finishdel(orderId);
        return Result.success(obj);
    }

    @PutMapping("/uncommit")
    public Result edit(@RequestBody OrderDetail orderDetail){
        Object obj = orderDetailService.edit(orderDetail);
        return Result.success(obj);
    }

    @GetMapping("/uncommit/{id}")
    public Result one(@PathVariable("id") Integer id){
        Object obj = orderDetailService.one(id);
        return Result.success(obj);
    }
    @GetMapping("/finish")
    public Result all(String realName){
        Object obj = orderDetailService.all(realName);
        return Result.success(obj);
    }

    @GetMapping("/uncommit/page")
    public Result page(Page page, OrderDetail orderDetail,HttpServletRequest request){
        //查询一共多少条数据
        //查询当前页要显示的数据
        //封装到page里面去
        String token = request.getHeader(SYS.TOKEN_AUTHORIZATION);
        orderDetailService.page(page,orderDetail,token);
        //返回page对象
        return Result.success(page);
    }

    @GetMapping("/uncommit/down/{id}")
    public Result cancel(@PathVariable("id") Integer id){
        int cancel = orderDetailService.cancel(id);
        return Result.success("删除订单成功",cancel);
    }

    @GetMapping("/uncommit/commit/{id}")
    public Result commit(@PathVariable("id") Integer id){
         String cancel = orderDetailService.commit(id);
        return Result.success(cancel);
    }


    @GetMapping("/commit/page")
    public Result commitPage(Page page, OrderDetail orderDetail, HttpServletRequest request){
        //查询一共多少条数据
        //查询当前页要显示的数据
        //封装到page里面去
        String token = request.getHeader(SYS.TOKEN_AUTHORIZATION);
        orderDetailService.commitPage(page,orderDetail,token);
        //返回page对象
        return Result.success(page);
    }

    @GetMapping("/finish/page")
    public Result finishPage(Page page, OrderDetail orderDetail){
        //查询一共多少条数据
        //查询当前页要显示的数据
        //封装到page里面去
        orderDetailService.finishPage(page,orderDetail);
        //返回page对象
        return Result.success(page);
    }
    @PutMapping("/finish")
    public Result finishEdit(@RequestBody OrderDetail orderDetail){
        Object obj = orderDetailService.finishEdit(orderDetail);
        return Result.success(obj);
    }






}
